package cmd

import (
	"fmt"
	"ginfwk/adapter/facade/cmd/action"
	"ginfwk/adapter/facade/cmd/server"
	"ginfwk/infrastructure/component/config"
	"github.com/spf13/cobra"
)

const Version = "1.0.0"

type RouterRegister interface {
	Register(cmd *cobra.Command)
}

type CmdRouter struct {
	action.Action
	server.Server
}

func (r *CmdRouter) Router() *cobra.Command {
	root := r.RootCmd()
	r.Register(root)
	return root
}

func (r *CmdRouter) RootCmd() *cobra.Command {
	rootCmd := &cobra.Command{
		Use:   "dingle",
		Short: "dingle is a very fast static site generator",
		Long: `A Fast and Flexible golang DDD framework for simplify most application. 
Complete documentation is available at https://llqhz.gitee.io
`,
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Printf("dingle version [%s], please use -h for more usages.\n", Version)
		},
	}

	// 指定全局参数
	rootCmd.PersistentFlags().StringVarP(&config.ConfigFile, "config", "c", "", "use specific config file given.")

	return rootCmd
}

func (c *CmdRouter) Register(root *cobra.Command) {
	// 加入action
	c.Action.Register(root)

	// 注册服务路由
	c.Server.Register(root)
}
